package com.nicho;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import com.nicho.dao.SRootDAO;
import com.nicho.util.CloseStream;

/*
 * @Author: 姜东浩
 * @Date: 2021-11-08 19:36:35
 * @LastEditors: 姜东浩
 * @LastEditTime: 2021-11-09 15:05:48
 * @Description: 当项目第一次运行时，初始化一个超级管理员，才能进行其他操作
 */
public class SRootInit {
    public static void main(String[] args) {
        
        ObjectOutputStream oos = null;

        // 保存超级管理员登录信息的文件目录
        File fileFolder = new File("src/com/nicho/file");
        File studentData = new File("src/com/nicho/file/StudentData.txt");
        File sRootData = new File("src/com/nicho/file/SRootData.txt");
        File courseData = new File("src/com/nicho/file/CourseData.txt");
        File teacherData = new File("src/com/nicho/file/TeacherData.txt");

        // 将管理员信息序列化进文件中
        try {
            if(!fileFolder.exists()){
                fileFolder.mkdirs();
            }
            studentData.createNewFile();
            sRootData.createNewFile();
            courseData.createNewFile();
            teacherData.createNewFile();
            oos = new ObjectOutputStream(new FileOutputStream(sRootData));
            oos.reset();
            oos.writeObject(new SRootDAO().initSRoot());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭流
            CloseStream.closeObjectOutputStream(oos);
        }

    }

}